package org.example.foodhealth.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;

import java.util.Properties;

@Configuration
public class MailConfig {
    @Bean
    public JavaMailSender mailSender() {
        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
        mailSender.setHost("smtp.qq.com"); // SMTP 服务器地址
        mailSender.setPort(465); // SMTP 端口

        mailSender.setUsername("178956409@qq.com"); // 发件人邮箱地址
        mailSender.setPassword("mgrivggfjqzwbjcf"); // 发件人邮箱的密码

        Properties props = mailSender.getJavaMailProperties();
        props.put("mail.transport.protocol", "smtp");
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.starttls.enable", "false"); // QQ 邮件不需要启用
        props.put("mail.smtp.socketFactory.port", "465");
        props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); // 启用 SSL
        props.put("mail.debug", "true"); // 启用调试输出

        return mailSender;
    }
}
